<template>
	<scroll-view scroll-y class="list c66 bgf5" @scrolltolower="nextPage">

		<view class="page bgf5 assistant">
			<swiper class="bgImg" circular autoplay>
				<swiper-item v-for="(item,index) in 2" :key="index">
					<image @click="join" src="https://img.quexiaqp.com/ruzhu.jpg" mode="aspectFill"></image>
				</swiper-item>
			</swiper>
			<view class="tabbox c66 fs17 flex flexC px15">
				<view v-for="(item,index) in tabs" @click="clickTab(index)" class="item p14 aliC" :key="index">
					<text :class="selIndex == index ? 'active' : ''">{{item.name}}</text>
					<image v-if="selIndex == index" class="icon" src="/static/img/icon/sel.png" mode="widthFix"></image>
				</view>
			</view>
			<assistant-item v-for="(item,index) in list" :lat="lat" :lng="lng" :item="item"
				:key="index"></assistant-item>

		</view>
	</scroll-view>
</template>

<script>
	export default {
		data() {
			return {
				tabs: [{
						name: '女助教'
					},
					{
						name: '男助教'
					}
				],
				selIndex: 0,
				lat: '28.2129183',
				lng: '112.88881136',
				page: 1,
				list: [],
				sex: 'girl',
				isLastPage: false,
				isnodata: false
			};
		},
		onTabItemTap: function(e) {
			console.log(e);
			uni.vibrateShort({
				success: function() {
					console.log('success');
				}
			});
		},
		onLoad() {
			this.getLocation();
		},

		methods: {
			join() {
				uni.navigateTo({
					url: '../apply/index'
				})
			},


			nextPage() {

				this.page = this.page + 1;
				if (this.isLastPage) return;
				this.getList();
			},

			clickTab(index) {
				console.info("===index==" + index);
				this.selIndex = index;
				if (index == 0) {
					this.sex = "girl";
				} else {
					this.sex = "boy";
				}
				this.page = 1;
				this.isnodata = false;
				this.isLastPage = false;
				this.list = [];
				this.getList();
			},

			getList() {
				let that = this;
				let param = {
					lat: this.lat,
					lng: this.lng,
					page: this.page,
					sex: this.sex
				};

				this.$api.assistAntList(param).then(res => {

					console.info(JSON.stringify(res));
					if (res.code == 1) {
						let length = res.data.length;
						for (let i = 0; i < length; i++) {
							that.list.push(res.data[i]);
						}
						if (length < 10) {
							this.isLastPage = true;
						}
						if (that.list.length > 0) {
							that.isnodata = false;
						} else {
							that.isnodata = true;
						}
					} else {

					}
				})
			},
			getLocation() {
				let that = this;
				uni.getLocation({
					type: 'gcj02',
					success: function(res) {
						console.log('当前位置的经度：' + res.longitude);
						console.log('当前位置的纬度：' + res.latitude);
						that.lat = res.latitude;
						that.lng = res.longitude;

						that.getList();
						uni.setStorageSync("lat", that.lat);
						uni.setStorageSync("lng", that.lng);

					},
					fail: function(res) {
						console.info("location  fail" + JSON.stringify(res))
					}
				})
			},
		}

	}
</script>

<style lang="scss" scoped>
	.assistant {
		.list {
			height: 100vh;
		}

		.tabbox {
			.item {
				position: relative;

				.active {
					color: #1A1B20;
					font-weight: 600;
				}

				.icon {
					width: 38rpx;
					height: 10rpx;
					position: absolute;
					bottom: 16rpx;
					left: calc(50% - 19rpx);
				}
			}
		}

		.bgImg {
			width: 100%;
			height: 378rpx;
			background-color: #FFF;

			image {
				width: 100%;
				height: 100%;
			}
		}
	}
</style>